#include <iostream>
using namespace std;
const int N = 1e5 + 10;
int map[26];
string s;
int count = 0;
int main() {
    int ans = 0;


    cin >> s;
    int n = s.size();

    int l = 0, r = 0;

    while (r < n)
    {

        if (map[s[r] - 'a'] == 0)
            count++;
        map[s[r] - 'a']++;

        while (count > 2)
        {
            if (map[s[l++] - 'a']-- == 1)
                count--;
        }

        ans = max(ans, r - l + 1);
        r++;

    }
    cout << ans << endl;

    return 0;
}